def pr(num):
    fl=True
    for i in range(2,num):
        if num%i==0:
            fl=False
            break
    return fl

s=input()
if s.count(" ")==2:
    a,b,c=s.split()
    m=['zero','one','two','three','four','five','six','seven','eight','nine']
    if a in m and b in m and c in m and a!='zero':
        num = m.index(a)*100+m.index(b)*10+m.index(c)
        if pr(num)==True:
            print(num)
        else:
            x=y=0
            for r in range(num+1,1100):
                if pr(r)==True:
                    x=r
                    break
            for l in range(num,0,-1):
                if pr(l)==True:
                    y=l
                    break
            if x-num < num-y:
                print(x)
            else:
                print(y)
    else:
        print("Wrong input")
    
else:
    print("Wrong input")
